package cn.edu.lit.jsjxy.CourseExample.chapter2;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import java.util.Random;

import cn.edu.lit.jsjxy.CourseExample.R;

public class UserLoginActivity extends Activity implements View.OnClickListener
{

    TextView tv1;
    Button btnOK;
    Button btnCancel;
    EditText etPassword;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_toast);

        ImageView iv1 = (ImageView) findViewById(R.id.iv1);
        tv1 = findViewById(R.id.tv1);

        btnOK = findViewById(R.id.btnOK);
        btnCancel = findViewById(R.id.btnCancel);

        etPassword = findViewById(R.id.etPassword);

        btnOK.setOnClickListener(this);
        btnCancel.setOnClickListener(this);

        //        btnOK.setOnClickListener(new View.OnClickListener() {
        //            @Override
        //            public void onClick(View view) {
        //                Toast.makeText(DialogActivity.this,"clicked",Toast.LENGTH_LONG).show();
        //            }
        //        });
    }

    public void onClick(View v)
    {
        //        final  int id1 = btnOK.getId();
        //        final  int id2 = btnCancel.getId();

        if (v.getId() == btnOK.getId()) {


            if (etPassword.getText().toString().equals("abc123")) {
                Toast.makeText(this, "right password", Toast.LENGTH_LONG).show();
            } else {
                Toast.makeText(this, "wrong password", Toast.LENGTH_LONG).show();
            }

        } else if (v.getId() == btnCancel.getId()) {
            Toast.makeText(this, "BtnCancel clicked", Toast.LENGTH_LONG).show();
        }


        Random random = new Random();
        int red = random.nextInt(256);
        int green = random.nextInt(256);
        int blue = random.nextInt(256);

        tv1.setBackgroundColor(Color.rgb(red, green, blue));

    }
}
